package com.wss.day02.test05;

/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/4/21
 */
public class User {
    private String name;
    private String address;
    private String phone;
    private Order[] orders;

    public User(String name, String address, String phone) {
        this.name = name;
        this.address = address;
        this.phone = phone;
        this.orders = new Order[0];
    }


    public Order placeOrder(long orderId, Goods[] goods) {
        Order newOrder = new Order(orderId, this, goods);

        // 将新订单添加到用户订单列表中
        Order[] newOrders = new Order[orders.length + 1];
        System.arraycopy(orders, 0, newOrders, 0, orders.length);
        newOrders[orders.length] = newOrder;
        this.orders = newOrders;

        System.out.println(name + " 下单成功，订单号：" + orderId);
        return newOrder;
    }

    public String getName() {
        return name;
    }

    public String getAddress() {
        return address;
    }

    public String getPhone() {
        return phone;
    }

    public Order[] getOrders() {
        return orders;
    }
}
